package com.koron.order.overhaul.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.order.overhaul.bean.vo.OrderDispatchVO;
import com.koron.order.overhaul.service.OverhaulOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author twcao
 * @title: OverhaulOrderDispatchController
 * @projectName GDH_EAM_V2
 * @description: 大修工单-待派工
 * @date 2021/10/219:05
 */
@Slf4j
@Api(tags = "大修工单-待派工")
@RestController
@RequestMapping("/overhaul/dispatch")
public class OverhaulOrderDispatchController {

    @Autowired
    private OverhaulOrderService overhaulOrderService;

    @ApiOperation(value = "待派工(status = 1)，新增或修改(派工信息，工作班组，工作班成员)，返回派工信息id")
    @PostMapping("/saveDispatchInfo")
    public Response<String> dispatch(@CasUser @ApiIgnore EamUser user, @RequestBody OrderDispatchVO vo) {
        log.info("待派工-新增或修改，vo = {}", JSON.toJSONString(vo));
        vo.setDeptId(StringUtils.isBlank(vo.getDeptId()) ? user.getOrgId() : vo.getDeptId());
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), overhaulOrderService, "dispatch", String.class, vo));
    }

    @ApiOperation(value = "待派工(status = 1)，根据工单id删除派工信息(包括工作班组和工作班成员)")
    @DeleteMapping("/deleteDispatchInfo")
    public Response<Boolean> deleteDispatchInfo(@CasUser @ApiIgnore EamUser user, @RequestParam String orderId) {
        log.info("待派工-删除派工信息，orderId = {}", orderId);
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), overhaulOrderService, "deleteDispatchInfo", Boolean.class, orderId));
    }

    @ApiOperation(value = "待派工(status = 1)，根据工单id查询派工详情")
    @GetMapping("/queryDispatchInfoByOrderId")
    public Response<OrderDispatchVO> queryDispatchInfoByOrderId(@CasUser @ApiIgnore EamUser user, @RequestParam String orderId) {
        log.info("根据工单id查询派工详情，orderId = {}", orderId);
        return Response.ok("操作成功", ADOConnection.runTask(user.getCurrDs(), overhaulOrderService, "queryDispatchInfoByOrderId", OrderDispatchVO.class, orderId));
    }
}
